import {baseUrl} from './config'
// 封装成类 -> 实例
class YLRequest {
  constructor(baseUrl) {
    this.baseUrl = baseUrl
  }
  request(options) {
    const { url } = options
    return new Promise((resolve,reject)=> {
      wx.request({
        ...options,
        url: this.baseUrl + url,
       success: (res)=> {
         resolve(res.data)
       },
       fail: (err)=> {
        reject(err)
       }
      })
    })
  }

  get(options) {
    return this.request({...options,method: 'get'})
  }

  post(options) {
    return this.request({...options,method: 'post'})
  }
}

export const ylRequest = new YLRequest(baseUrl)